﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CP2011_Assignment
{
    public partial class DeleteProductUI : Form
    {
        public DeleteProductUI()
        {
            InitializeComponent();
        }

        private void DeleteProductUI_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'assignmentDBDataSet1.Product' table. You can move, or remove it, as needed.
            this.productTableAdapter.Fill(this.assignmentDBDataSet1.Product);

        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (txtEnterId.Equals(""))
            {
                MessageBox.Show("Field Can't Be Empty", "Error");
            }
            else
            {
                TempStorage ts = new TempStorage();
                ts.setValue1(Convert.ToInt32(txtBoxProdId.Text));
                executeDelete(new ProductionSystem(), ts);
                this.Hide();
                this.Owner.Show();
                this.Dispose();
            }
        }
        private void executeDelete(IDataController dataCtrl, TempStorage tempStrge)
        {
            int invId = tempStrge.getValue1();
            if (MessageBox.Show("Do you want to delete record of Item ID: " + invId, "Confirm Deletion", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                dataCtrl.deleteRecord(tempStrge);
            }
        }

        private void DeleteProductUI_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.Hide();
            this.Owner.Show();
            this.Dispose();
        }

        private void btnBack_Click(object sender, EventArgs e)
        {
            this.Hide();
            this.Owner.Show();
            this.Dispose();
        }

    }
}
